package com.zhangmeng.online.exam.ui.module;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zm
 * @date 2025/3/31 15:33
 * @version: 1.0
 */
public class User {

    private int id;
    private String username;
    private String name;
    private String email;
    private String status;
    private String password;    // 加密后的密码
    private String salt;        // 密码盐值
    private List<Role> roles = new ArrayList<>();
    private String phone;
    private String avatarUrl;

    private String token;

    private String roleType;


    public User(int id, String username, String name, String email, String status) {
        this.id = id;
        this.username = username;
        this.name = name;
        this.email = email;
        this.status = status;
    }

    public User() {
    }

    public User(int id, String username, String name, String email, String status, String password, String salt) {
        this(id, username, name, email, status);
        this.password = password;
        this.salt = salt;
    }

    // Getters and Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public void addRole(Role role) {
        if (!roles.contains(role)) {
            roles.add(role);
        }
    }

    public boolean hasPermission(int permissionId) {
        return roles.stream()
                .anyMatch(role -> role.hasPermission(permissionId));
    }

    public boolean isEnabled() {
        return "启用".equals(status);
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }


    public String getRoleType() {
        return roleType;
    }

    public void setRoleType(String roleType) {
        this.roleType = roleType;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }
}
